package cn.jn.lhm.netty.part06;

import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufAllocator;
import lombok.extern.slf4j.Slf4j;

/**
 * @author lhm 2753914576@qq.com
 * @time 2023/7/17 - 22:51
 **/
@Slf4j
public class TestByteBuf {
    public static void main(String[] args) {
        // 会自动进行扩容
        ByteBuf buffer = ByteBufAllocator.DEFAULT.buffer(10);
        System.out.println("buffer = " + buffer);
        System.out.println(buffer.getClass());

        for (long i = 0; i < 3000; i++) {
            buffer.writeByte('a');
        }

        System.out.println("buffer = " + buffer);


        // 堆内存
        ByteBuf heapBuffer = ByteBufAllocator.DEFAULT.heapBuffer();
        System.out.println(heapBuffer.getClass());
        // 直接内存
        ByteBuf directBuffer = ByteBufAllocator.DEFAULT.directBuffer();
        System.out.println("directBuffer.getClass() = " + directBuffer.getClass());
    }
}
